package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");//mysql的驱动
            //2.与数据库建立连接
            Connection connection = DriverManager.getConnection(
                    //url格式是固定的     数据库地址     /数据库名?参数
                    "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                    "root",
                    "root"
            );
            System.out.println("与数据库建立连接！");
            //通过连接对象创建用于执行SQL语句的语句对象
            Statement statement = connection.createStatement();
            String sql = "UPDATE userinfo " +
                    " SET password='666666' " +
                    " WHERE username='张三'";
            int num = statement.executeUpdate(sql);
            if(num>0){
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败");
            }
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
